﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace GiaoDien
{
    class NhanVienDAO
    {
		#region themNhanVien
        public static bool themNhanVien(NhanVienDTO nvDTO)
        {
            string sQuery = "insert into NhanVien(Manhanvien,Tennhanvien,Ngaysinh,Diachi,Loaichucvu) values(" + nvDTO.MaNhanVien + ",'" + nvDTO.TenNhanVien + "','" +
                nvDTO.NgaySinh + "','" + nvDTO.DiaChi + "'," + nvDTO.LoaiChucVu + ")";
            OleDbConnection con = DataProvider.taoKetNoi();
            bool ketqua = DataProvider.executeNonQuery(sQuery, con);
            DataProvider.dongKetNoi(con);
            return ketqua;
        }
        #endregion
		
		#region LayChiTietNhanVien
        public static DataTable LayChiTietNhanVien(NhanVienDTO nvDTO)
        {
            string sQuery = "select * from NhanVien order by Manhanvien";
            OleDbConnection con = DataProvider.taoKetNoi();
            DataTable da = DataProvider.layDataTable(sQuery, con);
            DataProvider.dongKetNoi(con);
            return da;
        }
        #endregion

		#region CapNhapNhanVien
		public static bool CapNhapNhanVien(NhanVienDTO nvDTO)
        {
            string sQuery = "update NhanVien set Tennhanvien='" + nvDTO.TenNhanVien + "',Ngaysinh='" + nvDTO.NgaySinh + "',Diachi='" + nvDTO.DiaChi + "',Loaichucvu=" + nvDTO.LoaiChucVu + " where Manhanvien=" + nvDTO.MaNhanVien;
            OleDbConnection con = DataProvider.taoKetNoi();
            bool ketqua = DataProvider.executeNonQuery(sQuery, con);
            DataProvider.dongKetNoi(con);
            return ketqua;
        }
		#endregion
		
		#region XoaNhanVien
		public static bool XoaNhanVien(NhanVienDTO nvDTO)
        {
            string sQuery = "delete from NhanVien where Manhanvien=" + nvDTO.MaNhanVien;
            OleDbConnection con = DataProvider.taoKetNoi();
            bool ketqua = DataProvider.executeNonQuery(sQuery, con);
            DataProvider.dongKetNoi(con);
            return ketqua;
        }
		#endregion
    }
}
